package qlsl.androiddesign.adapter.subadapter;

import java.util.List;

import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.adapter.baseadapter.BaseAdapter;
import qlsl.androiddesign.entity.otherentity.ShoppingDetail;
import qlsl.androiddesign.util.commonutil.ImageUtils;
import qlsl.androiddesign.util.commonutil.TextSizeUtils;
import qlsl.androiddesign.util.commonutil.TimeFormatUtils;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qlsl.androiddesign.kuaiwa.R;

public class ShoppingListAdapter extends BaseAdapter<ShoppingDetail> {

	public ShoppingListAdapter(BaseActivity activity, List<ShoppingDetail> list) {
		super(activity, list);
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = getItemView(convertView, R.layout.listitem_shopping_list);

		TextView tv_text_addr = getView(convertView, R.id.vehicle_fragment_item_address);
		TextView tv_text = getView(convertView, R.id.vehicle_fragment_item_title);
		TextView tv_text_price = getView(convertView, R.id.vehicle_fragment_item_price1);
		TextView tv_text_price2 = getView(convertView, R.id.vehicle_fragment_item_price);
		TextView tv_text_time = getView(convertView, R.id.vehicle_fragment_item_text_time);

		ImageView iv_icon = getView(convertView, R.id.vehicle_fragment_item_img);

		ShoppingDetail item = getItem(position);
		ImageUtils.rect(activity, item.getPhoto(), iv_icon);

		tv_text.setText(item.getGoodsname());
		tv_text_addr.setText("销量: " + item.getSales() + "件");
		tv_text_price.setText("价格: ￥" + item.getNewprice() + "元");

		TextSizeUtils.setTextCenterLine(tv_text_price2);
		if (!TextUtils.isEmpty(item.getOldprice()) && item.getOldprice() != null) {
			tv_text_price2.setText("" + item.getOldprice() + "元");
		} else {
			tv_text_price2.setText("");
		}

		if (!TextUtils.isEmpty(item.getTime()) && item.getTime() != null) {
			tv_text_time.setText("" + TimeFormatUtils.format(item.getTime()));
		} else {
			tv_text_time.setText("");
		}

		return convertView;
	}
}
